package root.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;

import root.entity.po.LiuYan1;
import root.entity.vo.PageInfo;
import root.service.LybDataService;
import root.service.impl.LybDataServiceimpl;

/**
 * Servlet implementation class Lybflushdata
 */
//@WebServlet("/lybflushdata")
public class Lybflushdata extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Lybflushdata() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		PrintWriter writer = response.getWriter(); 
		
		//获取信息
		String name = request.getParameter("name");
		String value = request.getParameter("value");
		String type = request.getParameter("type");
		String target = request.getParameter("target");
		String fenyepageindex = request.getParameter("fenyepageindex");
		PageInfo page = new PageInfo();
		//检查数据为空
		if(fenyepageindex==null || fenyepageindex.equals("")) {
			writer.write("error");
			writer.close();
			return;
		}
//		检查是数字
		try {
			page.setFenyepageindex(Integer.valueOf(fenyepageindex));
		} catch (Exception e) {
			writer.write("error");
			writer.close();
			return;
		}
		
		//执行业务
		LybDataService service = new LybDataServiceimpl();
		service.flushData(name,value,type,target,page);
		
//		序列化  JSON串
//		fastjson  alibaba
		writer.write(JSON.toJSONString(page));
		writer.close();
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
